# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=aarch64 -run-pass=legalizer %s -o - -verify-machineinstrs | FileCheck %s

...
---
name:            bswap_s16
tracksRegLiveness: true
body:             |
  bb.1:
    liveins: $w0

    ; CHECK-LABEL: name: bswap_s16
    ; CHECK: liveins: $w0
    ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[COPY]]
    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
    ; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BSWAP]], [[C]](s64)
    ; CHECK: $w0 = COPY [[LSHR]](s32)
    ; CHECK: RET_ReallyLR implicit $w0
    %1:_(s32) = COPY $w0
    %0:_(s16) = G_TRUNC %1(s32)
    %2:_(s16) = G_BSWAP %0
    %3:_(s32) = G_ANYEXT %2(s16)
    $w0 = COPY %3(s32)
    RET_ReallyLR implicit $w0
...
---
name:            bswap_s32_legal
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: bswap_s32_legal
    ; CHECK: liveins: $w0
    ; CHECK: %copy:_(s32) = COPY $w0
    ; CHECK: %bswap:_(s32) = G_BSWAP %copy
    ; CHECK: $w0 = COPY %bswap(s32)
    ; CHECK: RET_ReallyLR implicit $w0
    %copy:_(s32) = COPY $w0
    %bswap:_(s32) = G_BSWAP %copy
    $w0 = COPY %bswap(s32)
    RET_ReallyLR implicit $w0
...
---
name:            bswap_s64_legal
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0
    ; CHECK-LABEL: name: bswap_s64_legal
    ; CHECK: liveins: $x0
    ; CHECK: %copy:_(s64) = COPY $x0
    ; CHECK: %bswap:_(s64) = G_BSWAP %copy
    ; CHECK: $x0 = COPY %bswap(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %copy:_(s64) = COPY $x0
    %bswap:_(s64) = G_BSWAP %copy
    $x0 = COPY %bswap(s64)
    RET_ReallyLR implicit $x0
...
---
name:            bswap_v4s32_legal
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $q0
    ; CHECK-LABEL: name: bswap_v4s32_legal
    ; CHECK: liveins: $q0
    ; CHECK: %copy:_(<4 x s32>) = COPY $q0
    ; CHECK: %bswap:_(<4 x s32>) = G_BSWAP %copy
    ; CHECK: $q0 = COPY %bswap(<4 x s32>)
    ; CHECK: RET_ReallyLR implicit $q0
    %copy:_(<4 x s32>) = COPY $q0
    %bswap:_(<4 x s32>) = G_BSWAP %copy
    $q0 = COPY %bswap(<4 x s32>)
    RET_ReallyLR implicit $q0
...
---
name:            bswap_v2s32_legal
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $d0
    ; CHECK-LABEL: name: bswap_v2s32_legal
    ; CHECK: liveins: $d0
    ; CHECK: %copy:_(<2 x s32>) = COPY $d0
    ; CHECK: %bswap:_(<2 x s32>) = G_BSWAP %copy
    ; CHECK: $d0 = COPY %bswap(<2 x s32>)
    ; CHECK: RET_ReallyLR implicit $d0
    %copy:_(<2 x s32>) = COPY $d0
    %bswap:_(<2 x s32>) = G_BSWAP %copy
    $d0 = COPY %bswap(<2 x s32>)
    RET_ReallyLR implicit $d0
...
---
name:            bswap_v2s64_legal
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $q0
    ; CHECK-LABEL: name: bswap_v2s64_legal
    ; CHECK: liveins: $q0
    ; CHECK: %copy:_(<2 x s64>) = COPY $q0
    ; CHECK: %bswap:_(<2 x s64>) = G_BSWAP %copy
    ; CHECK: $q0 = COPY %bswap(<2 x s64>)
    ; CHECK: RET_ReallyLR implicit $q0
    %copy:_(<2 x s64>) = COPY $q0
    %bswap:_(<2 x s64>) = G_BSWAP %copy
    $q0 = COPY %bswap(<2 x s64>)
    RET_ReallyLR implicit $q0
...
---
name:            bswap_s88
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0
    ; CHECK-LABEL: name: bswap_s88
    ; CHECK: liveins: $x0
    ; CHECK: [[DEF:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
    ; CHECK: [[BSWAP:%[0-9]+]]:_(s64) = G_BSWAP [[DEF]]
    ; CHECK: [[BSWAP1:%[0-9]+]]:_(s64) = G_BSWAP [[DEF]]
    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 40
    ; CHECK: [[LSHR:%[0-9]+]]:_(s64) = G_LSHR [[BSWAP]], [[C]](s64)
    ; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 24
    ; CHECK: [[SHL:%[0-9]+]]:_(s64) = G_SHL [[BSWAP1]], [[C1]](s64)
    ; CHECK: [[OR:%[0-9]+]]:_(s64) = G_OR [[LSHR]], [[SHL]]
    ; CHECK: $x0 = COPY [[OR]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %val:_(s88) = G_IMPLICIT_DEF
    %bswap:_(s88) = G_BSWAP %val
    %trunc:_(s64) = G_TRUNC %bswap
    $x0 = COPY %trunc(s64)
    RET_ReallyLR implicit $x0
...
---
name:            bswap_s4
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0
    ; CHECK-LABEL: name: bswap_s4
    ; CHECK: liveins: $x0
    ; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
    ; CHECK: [[BSWAP:%[0-9]+]]:_(s32) = G_BSWAP [[DEF]]
    ; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 28
    ; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[BSWAP]], [[C]](s64)
    ; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 15
    ; CHECK: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[LSHR]](s32)
    ; CHECK: %ext:_(s64) = G_AND [[ANYEXT]], [[C1]]
    ; CHECK: $x0 = COPY %ext(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %val:_(s4) = G_IMPLICIT_DEF
    %bswap:_(s4) = G_BSWAP %val
    %ext:_(s64) = G_ZEXT %bswap
    $x0 = COPY %ext(s64)
    RET_ReallyLR implicit $x0
